﻿using System;
using System.Collections.Generic;

namespace Citi.HeadCount.Domain
{
    public class Function : EntityBase
    {
        public virtual string Code { get; set; }
        public virtual string Description { get; set; }
        public virtual int? ParentId { get; set; }
        public virtual string ParentCode { get; set; }
        public virtual int TreeLevel { get; set; }
        public virtual char Status { get; set; }
        public virtual string Definition { get; set; }

        public virtual Function Parent { get; set; }

        public override bool IsSameInformation(EntityBase entity)
        {
            var function = (Function)entity;

            return Code == function.Code
               && Description == function.Description
               && ((ParentId == function.ParentId || ParentId == Id) || (ParentCode == function.ParentCode || ParentCode == Code))
               && Status == function.Status;
        }
    }

    public class FunctionComparer : IEqualityComparer<Function>
    {
        public bool Equals(Function x, Function y)
        {
            if (Object.ReferenceEquals(x, y)) return true;

            if (Object.ReferenceEquals(x, null) || Object.ReferenceEquals(y, null))
                return false;

            return x.Code == y.Code && x.Id == y.Id;
        }

        public int GetHashCode(Function item)
        {
            if (Object.ReferenceEquals(item, null)) return 0;

            int hashDescription = item.Description == null ? 0 : item.Description.GetHashCode();
            int hashId = item.Description == null ? 0 : item.Id.GetHashCode();

            return hashDescription ^ hashId;
        }

    }
}
